Page({
    //初始化数据
    data: {
        array: ['大中国', '美国', '巴西', '小日本'],
        index: 0,
        date: '2016-12-20',
        time: '11:19',
        allValue: '',
        index: 0,
        multiIndex: [0, 0],
        //传到后台的课程分类
        cname: '',
        imgs: [],
        proof: ''
    },
    chooseImg: function (e) {
        var that = this;
        console.log(that);
        if (that.data.cname == '') {

        } else {
            var imgs = this.data.imgs;
            if (imgs.length >= 9) {
                this.setData({
                    lenMore: 1
                });
                setTimeout(function () {
                    that.setData({
                        lenMore: 0
                    });
                }, 2500);
                return false;
            }
        }

        wx.chooseImage({
            // count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                var tempFilePaths = res.tempFilePaths;
                var imgs = that.data.imgs;
                console.log(res, 5255);
                // console.log(tempFilePaths + '----');
                for (var i = 0; i < tempFilePaths.length; i++) {
                    if (imgs.length >= 9) {
                        that.setData({
                            imgs: imgs
                        });
                        return false;
                    } else {
                        imgs.push(tempFilePaths[i]);
                    }
                }
                // console.log(imgs);
                that.setData({
                    imgs: imgs,
                });
                //循环把图片上传到服务器
                for (var i = 0; i < imgs.length; i++) {
                    wx.uploadFile({
                        url: 'http://www.week.com/api/upload/uploadimg',
                        filePath: imgs[i],
                        name: 'files',
                        formData: {
                            cname: that.data.cname
                        },
                        success: function (res) {
                            console.log(res.data)
                            var hhsd = res.data.replace(/\"/g, "");
                            that.data.proof = that.data.proof.concat(hhsd + ',');
                            that.setData({
                                proof: that.data.proof
                            });
                        }
                    })
                }
            }
        });

    },
    deleteImg: function (e) {
        var imgs = this.data.imgs;
        var index = e.currentTarget.dataset.index;
        imgs.splice(index, 1);
        this.setData({
            imgs: imgs
        });
    },

    // 预览图片
    previewImg: function (e) {
        //获取当前图片的下标
        var index = e.currentTarget.dataset.index;
        //所有图片
        var imgs = this.data.imgs;
        wx.previewImage({
            //当前显示图片
            current: imgs[index],
            //所有图片
            urls: imgs
        })
    },

    //表单提交按钮
    formSubmit: function (e) {
        console.log(e);
        console.log('form发生了submit事件，携带数据为：', e.detail.value)
        this.setData({
            allValue: e.detail.value
        })
    },
    //表单重置按钮
    formReset: function (e) {
        console.log('form发生了reset事件，携带数据为：', e.detail.value)
        this.setData({
            allValue: ''
        })
    },
    //---------------------与选择器相关的方法
    //地区选择
    bindPickerChange: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index: e.detail.value
        })
    },
    //日期选择
    bindDateChange: function (e) {
        this.setData({
            date: e.detail.value
        })
    },
    //时间选择
    bindTimeChange: function (e) {
        this.setData({
            time: e.detail.value
        })
    },

})